﻿using MediatR;
using T_settlement.API.Application.Command.PaymentCommand;
using T_settlement.Domain;
using T_settlement.Infrastructure.Interfacec;

namespace T_settlement.API.Application.CommandHandlers.PaymentCommandHandlers
{
    public class UpdatePaymentCommandHandlers:IRequestHandler<UpdatePaymentCommand,int>
    {
        private readonly IPaymentRepository paymentRepository;

        public UpdatePaymentCommandHandlers(IPaymentRepository paymentRepository)
        {
            this.paymentRepository = paymentRepository;
        }

        public async Task<int> Handle(UpdatePaymentCommand request, CancellationToken cancellationToken)
        {
            var info = new Payment();
            info.Title = request.Title;
            info.Description = request.Description;
            info.PaymentMoney = request.PaymentMoney;
            info.SettlType = request.SettlType;
            info.Tinning = request.Tinning;
            info.Bank = request.Bank;
            info.BankAccount = request.BankAccount;
            info.CreateBy = "王小宝";
            info.PaymentTime = request.PaymentTime;
            info.Remark = request.Remark;
            info.CreateDate = DateTime.Now;
            info.PaymentId = request.PaymentId;
            info.AuditState = request.AuditState = -1;//待提交
            info.InvoiceImg = request.InvoiceImg;
            return await paymentRepository.UpdateAsync(info);
        }
    }
}
